﻿using CPF;
using CPF.Animation;
using CPF.Charts;
using CPF.Controls;
using CPF.Drawing;
using CPF.Input;
using CPF.Shapes;
using CPF.Styling;
using CPF.Svg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CPFUI.IControl
{
    [CPF.Design.DesignerLoadStyle("res://$safeprojectname$/Stylesheet1.css")]//用于设计的时候加载样式
    public class MenuControlItem : Control
    {
        public string Text
        {
            get { return GetValue<string>(); }
            set
            {
                SetValue(value);
            }
        }
        public string Image
        {
            get { return GetValue<string>(); }
            set
            {
                SetValue(value);
            }
        }
        //模板定义
        protected override void InitializeComponent()
        {
            CornerRadius = "8";
            Cursor = Cursors.Hand;
            Children.Add(new StackPanel
            {
                Orientation = Orientation.Horizontal,
                MarginLeft = 0,
                MarginRight = 0,
                Height = 30,
                Background = null,
                Children ={
                    new Picture
                    {
                        MarginLeft=8,
                        Width = 20,
                        Height = 20,
                        Stretch = Stretch.Uniform,
                        Bindings =
                        {
                            {
                                nameof(Picture.Source),
                                nameof(Image),
                                this
                            },
                        }
                    },
                    new TextBlock{
                        MarginLeft=10,
                        Text="地磁",

                        Bindings =
                        {
                            {
                                nameof(TextBlock.Text),
                                nameof(Text),
                                this,
                                BindingMode.TwoWay
                            },
                            {
                                nameof(TextBlock.Foreground),
                                nameof(Foreground),
                                this,
                                BindingMode.TwoWay
                            }
                        },
                    }
                },
                Commands =
                {
                    {
                        "MouseDown",
                        nameof(StackPanelMouseDown),
                        this,
                        CommandParameter.EventSender,
                        CommandParameter.EventArgs
                    },
                }
            });
        }

#if !DesignMode //用户代码写到这里，设计器下不执行，防止设计器出错
        protected override void OnInitialized()
        {
            base.OnInitialized();

        }
        //用户代码
        private void StackPanelMouseDown(CpfObject sender, MouseButtonEventArgs e)
        {
            OnMenuClick?.Invoke(sender, e);
        }
        public event EventHandler<MouseButtonEventArgs> OnMenuClick;
#endif
    }
}
